package com.struts2.action;

import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.interceptor.validation.SkipValidation;

import com.struts2.model.Designer;
import com.struts2.service.AdminService;
import com.struts2.service.LoginService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class AdminLoginAction extends ActionSupport implements SessionAware {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static final String adminUsername = "abc";
	private static final String adminpwd = "123";

	private String username="";
	private String password="";

	// For SessionAware
	private Map<String, Object> session;

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

/*	public void validate() {
		if (StringUtils.isEmpty(username)) {
			addActionError("User Name cannot be blank");
		}
		if (StringUtils.isEmpty(password)) {
			addActionError("Password cannot be blank");
		}
	}*/

	public String execute() {
		if (username.equals(adminUsername)  && password.equals(adminpwd)) {
			session.put("adminLogin", "hihi");
			System.out.print("fdsfdsfsf");
			
			
			AdminService as = new AdminService();
			int num= as.getProductNotApproval();
			session.put("productsNotApproval", num);
			
			
			session.put("DesignersNotApproval", as.getDesignerNotApproval());
			session.put("InvoiceFail", as.getInvoiceFailCnt());

			
			
			return "success";
		}
		
		System.out.print("rgregwg");

		return "login";
	}

//	@SkipValidation
	public String logout() {
		session.remove("adminLogin");
		return SUCCESS;
	}

	// //////////////////////////////////////////////////////////////////////////////////////////////////////

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	// //////////////////////////////////////////////////////////////////////////////////////////////////////

}
